import api from '@/api';
const CALL_SIDEBAR_TRUE = 'CALL_SIDEBAR_TRUE';
const CALL_SIDEBAR_FLASE = 'CALL_SIDEBAR_FLASE';
const SETTEL = 'SETTEL';
const SET_COUNTRY_NAME = 'SET_COUNTRY_NAME';
const SET_PAGES_TITLE = 'SET_PAGES_TITLE';
const SET_DIAL_STATUS = 'SET_DIAL_STATUS';
const SET_RECORDS_LIST = 'SET_RECORDS_LIST';
const state = {
  isCall: false,
  telephone: '',
  countryName: '',
  pageTitle: '',
  dialStatus: '',
  recordsList: []
};

const getters = {
  isCall: state => state.isCall,
  telephone: state => state.telephone,
  countryName: state => state.countryName,
  pageTitle: state => state.pageTitle,
  dialStatus: state => state.dialStatus,
  recordsList: state => state.recordsList
};

const actions = {
  getRecordsList({ commit }, msisdn) {
    // console.log(this._vm);
    this._vm.$loading('加载中');
    api.app.recordsList({ page: 1, msisdn: msisdn }).then(res => {
      commit(SET_RECORDS_LIST, res.result);
      this._vm.$loading.close();
    }).catch((data) => {
      this._vm.$loading.close();
    });
  },
  setPageTitle({ commit }, data) {
    commit(SET_PAGES_TITLE, data);
  },
  setDialStatus({ commit }, data) {
    commit(SET_DIAL_STATUS, data);
  },
  setTelephone({ commit }, data) {
    commit(SETTEL, data);
  },
  setCountryName({ commit }, data) {
    commit(SET_COUNTRY_NAME, data);
  },
  toggleCallTrue({ commit }) {
    commit(CALL_SIDEBAR_TRUE);
  },
  toggleCallFlase({ commit }) {
    commit(CALL_SIDEBAR_FLASE);
  }
};

const mutations = {
  [SET_RECORDS_LIST](state, data) {
    state.recordsList = data;
  },
  [SET_DIAL_STATUS](state, data) {
    state.dialStatus = data;
  },
  [SET_PAGES_TITLE](state, data) {
    state.pageTitle = data;
  },
  [SET_COUNTRY_NAME](state, data) {
    state.countryName = data;
  },
  [SETTEL](state, data) {
    state.telephone = data;
  },
  [CALL_SIDEBAR_TRUE](state) {
    state.isCall = true;
  },
  [CALL_SIDEBAR_FLASE](state) {
    state.isCall = false;
  }
};

export default {
  state,
  getters,
  actions,
  mutations
};
